#
#	Makefile for proxy
#

CC = gcc
CFLAGS = -Wall -O2 -Wsign-compare
LDFLAGS = -lpthread -static

TARGET = proxyd proxyd1 proxyd2 proxyd3 proxyd4
OBJS = ip_addr.o cpu_util.o sock_util.o objpool.o session.o \
       packet.o thread.o nb_splice.o

ifneq (".deps", "$(wildcard .deps)")
	DEPDIR = .deps
endif


.PHONY : all clean depclean


all : $(TARGET)

# proxyd, using 1 accept, many work thread(2 epoll).
proxyd : $(OBJS) accept.o work.o proxy.o main.o 
	$(CC) -o $@ $^ $(LDFLAGS)

# proxyd1, using many work1 thread(2 epoll).
proxyd1 : $(OBJS) work1.o proxy1.o main.o
	$(CC) -o $@ $^ $(LDFLAGS)

# proxyd2, using same number accept2/work2 thread(2 epoll).
proxyd2 : $(OBJS) proxy2.o work2.o accept2.o main.o
	$(CC) -o $@ $^ $(LDFLAGS)

# proxyd3, using many work3 thread(1 epoll).
proxyd3 : $(OBJS) work3.o proxy1.o main.o
	$(CC) -o $@ $^ $(LDFLAGS)

# proxyd4, using many work4 thread(1 epoll), using fd_epoll.
proxyd4 : $(OBJS) work4.o proxy1.o main.o
	$(CC) -o $@ $^ $(LDFLAGS)


clean :
	rm -f *.o $(TARGET) $(TEST)

depclean : 
	rm -rf *.o $(TARGET) $(TEST) .deps 

test : $(TEST)

%.o : %.c $(DEPDIR)
	$(CC) $(CFLAGS) -c -o $@ $< -MD -MF .deps/$(<:.c=.d)

$(DEPDIR) :
	mkdir -p .deps

-include .deps/*.d


